package Euler45;

import java.math.BigInteger;
import java.util.*;

public class Shapes {
	public static void main(String[] args) {		
		List<BigInteger> triangle = new ArrayList<BigInteger>();
		List<BigInteger> pentagonal = new ArrayList<BigInteger>();
		List<BigInteger> hexagonal = new ArrayList<BigInteger>();
		List<BigInteger> collisions = new ArrayList<BigInteger>();
		
		for(int i = 1; i<500000; i++)
		{
			triangle.add((new BigInteger(String.valueOf(i)).multiply((new BigInteger(String.valueOf(i)).add(BigInteger.ONE)))).divide(new BigInteger(String.valueOf("2"))));
			pentagonal.add((new BigInteger(String.valueOf(i)).multiply((new BigInteger(String.valueOf(i)).multiply((new BigInteger("3"))).subtract(BigInteger.ONE)))).divide((new BigInteger("2"))));
			hexagonal.add((new BigInteger(String.valueOf(i)).multiply((new BigInteger(String.valueOf(i)).multiply((new BigInteger("2"))).subtract(BigInteger.ONE)))));
		}
		
		System.out.println(triangle.size());
		
		Collections.sort(triangle);
		Collections.sort(pentagonal);
		Collections.sort(hexagonal);
		
		BigInteger triMax = Collections.max(triangle);
		for(int i = 1; i < triangle.size(); i++)
		{
			BigInteger temp = hexagonal.get(i);
			
			if(Collections.binarySearch(pentagonal, temp) >= 0)
			{
				if(Collections.binarySearch(triangle, temp) >= 0)
				{
					System.out.println(i);
					collisions.add(temp);
				}
			}
			
			if(triMax.compareTo(temp)<0)
			{
				break;
			}
		}
		
		System.out.println(collisions);
		
		//System.out.println(triangle);
		//System.out.println(pentagonal);
		//System.out.println(hexagonal);
	}
}
